import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2023-02-22
 * Time: 17:11
 */
//treeset的底层就是treemap(搜索树)
    //set不能重复,因为map的key不能重复
    //
public class SetTest {
    public static void main(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("喜洋洋");
        set.add("美羊羊");
        set.add("沸羊羊");
        System.out.println(set);
        System.out.println("集合里元素的个数:"+set.size());
        System.out.println(set.contains("美羊羊"));
        //集合遍历
        System.out.println("====集合遍历======");
        Iterator<String> iterator= set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("集合里的个数"+set.size());
        System.out.println("判断集合是否为空"+set.isEmpty());
        //判断Collection里的数据是否在set中全部存在
        System.out.println("判断Collection里的数据是否在set中全部存在");
        Collection<String> collection = new ArrayList<>();
        collection.add("喜洋洋");
        collection.add("美羊羊");
        System.out.println(set.containsAll(collection));
//将collection里的全部元素添加到set里,可以达到去重的效果
        System.out.println(set.addAll(collection));
        //将set集合转为数组
       Object[]strings =  set.toArray();
        System.out.println(Arrays.toString(strings));
        //删除结合中的元素
        set.remove("美羊羊");
        System.out.println(set);
        System.out.println("清空集合");
        set.clear();
        System.out.println(set);



    }
}
